package com.proton.carepatchtemp.utils;

import android.os.Handler;
import android.os.Looper;

import com.proton.carepatchtemp.application.VCare;

import java.util.concurrent.ExecutorService;


/**
 * Created by Api on 2016/9/22.
 */

public class ThreadUtils {

    public static final long DELAY_CHART_ECG = 50;

    public static void runOnOtherThread(Runnable runnable) {
        final ExecutorService cachePool = VCare.get().getCachePool();
        cachePool.execute(runnable);
    }

    public static void runOnOtherThread(final Runnable runnable, long delay) {
        final ExecutorService cachePool = VCare.get().getCachePool();
        Handler handler = new Handler(Looper.getMainLooper());
        handler.postDelayed(() -> cachePool.execute(runnable), delay);
    }

    //按照线程添加顺序执行
    public static void postMsg(Runnable pRunnable) {
        final ExecutorService msgPool = VCare.get().getMsgPool();
        msgPool.execute(pRunnable);
    }

    public static void postCacheData(Runnable runnable) {
        final ExecutorService cacheDataPool = VCare.get().getCacheDataPool();
        cacheDataPool.execute(runnable);
    }

    public static void clear() {

    }
}
